package com.zz.forum.common;

import lombok.Data;

@Data
public class AppResult <T> {
    private int code;
    private String msg;
    private T data;

    public AppResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public AppResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 成功
     * @return AppResult<T>
     */
    public static  AppResult success() {
        return new AppResult<>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage());
    }

    public static  AppResult success(String msg) {
        return new AppResult(ResultCode.SUCCESS.getCode(), msg);
    }

    public static <T> AppResult<T> success(String msg, T data) {
        return new AppResult<T>(ResultCode.SUCCESS.getCode(), msg, data);
    }

    public static <T> AppResult<T> success(T data) {
        return new AppResult<T>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data);
    }

    /**
     * 失败
     */
     public static  AppResult failed() {
         return new AppResult(ResultCode.FAILED.getCode(),ResultCode.FAILED.getMessage());
     }

     public static  AppResult failed(String msg) {
         return new AppResult(ResultCode.FAILED.getCode(), msg);
     }

     public static  AppResult failed(ResultCode resultCode) {
         return new AppResult(resultCode.getCode(), resultCode.getMessage());
     }


}
